﻿/****************************** Module Header ******************************\
 * Module Name:  ExMethodForDataGridView.cs
 * Module Version:  1.0.0 (2012-6-5)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to extension winformcontrol instance's method.  It supplies 
 * public static extension methods to load data or get othor control.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace UCF.Core.Forms
{
    /// <summary>
    /// ExMethodForDataGridView控件扩展方法
    /// </summary>
    public static class ExMethodForDataGridView
    {
        /// <summary>
        /// 设置表格头显示序号
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="e"></param>
        public static void SetRowHeaderIndex(this DataGridView dgv, int posX = 13, int rowHeadersWidth = 32, int posY = 5)
        {
            dgv.RowHeadersWidth = rowHeadersWidth;
            dgv.RowPostPaint += (object s, DataGridViewRowPostPaintEventArgs e) =>
            {
                SolidBrush b = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor);
                e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + posX, e.RowBounds.Location.Y + posY);
            };
        }

        /// <summary>
        /// 设置表格列的自动尺寸模式
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="dt"></param>
        /// <param name="fillColumn"></param>
        /// <param name="fillColumnMiniWidth"></param>
        public static void SetDataSourceUI(this DataGridView dgv, object dt, DataGridViewColumn fillColumn = null, int fillColumnMiniWidth = 0)
        {
            dgv.DataSource = dt;
            dgv.AutoResizeColumns();
            foreach (DataGridViewColumn c in dgv.Columns)
            {
                c.MinimumWidth = 80;
            }
            if (fillColumn != null)
            {
                fillColumn.MinimumWidth = fillColumn.Width;
                fillColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }

        /// <summary>
        /// 设置表格列的自动尺寸模式
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="dt"></param>
        /// <param name="fillColumn"></param>
        /// <param name="fillColumnMiniWidth"></param>
        public static void SetDataSourceUI(this DataGridView dgv, object dt, int fillColumnIndex, int fillColumnMiniWidth = 0)
        {
            dgv.DataSource = dt;
            dgv.AutoResizeColumns();
            foreach (DataGridViewColumn c in dgv.Columns)
            {
                c.MinimumWidth = 80;
            }
            if (fillColumnIndex > -1)
            {
                dgv.Columns[fillColumnIndex].MinimumWidth = dgv.Columns[fillColumnIndex].Width;
                dgv.Columns[fillColumnIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }

        /// <summary>
        /// 获取表格指定列的所有值
        /// </summary>
        /// <typeparam name="V"></typeparam>
        /// <param name="dgv"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        public static IList<string> GetListOfValueByColumn(this DataGridView dgv, int columnIndex)
        {
            IList<string> list = new List<string>();
            foreach (DataGridViewRow r in dgv.Rows)
            {
                list.Add(r.Cells[columnIndex].Value.ToString());
            }
            return list;
        }

        /// <summary>
        /// 获取所有选中的值
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="checkboxColumnIndex"></param>
        /// <param name="valueColumnName"></param>
        /// <returns></returns>
        public static IList<string> GetListOfCheckedValue(this DataGridView dgv, int checkboxColumnIndex, string valueColumnName)
        {
            IList<string> list = new List<string>();
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                if ((bool)dgv.Rows[i].Cells[checkboxColumnIndex].EditedFormattedValue == true)
                {
                    list.Add(dgv.Rows[i].Cells[valueColumnName].Value.ToString());
                }
            }
            return list;
        }

        /// <summary>
        /// 统计某列的和
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="colName"></param>
        /// <returns></returns>
        public static double Sum(this DataGridView dgv, string colName)
        {
            double dsum = 0.00;
            foreach (DataGridViewRow r in dgv.Rows)
            {
                if (r.Cells[colName].Value != null) dsum += r.Cells[colName].Value.ToString().ToDouble();
            }
            return dsum;
        }

        /// <summary>
        /// 勾选表格中的复选框,勾选行变色
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="columnIndex"></param>
        /// <param name="e"></param>
        public static void OnClickCheckCheckBox(this DataGridView dgv, int columnIndex, Action<bool, DataGridViewRow> act = null)
        {
            dgv.CellContentClick += (object s, DataGridViewCellEventArgs e) =>
            {
                DataGridView oDgv = (DataGridView)s;
                if (e.RowIndex == -1) return;
                if ((bool)oDgv.Rows[e.RowIndex].Cells[columnIndex].EditedFormattedValue == true)
                {
                    oDgv.Rows[e.RowIndex].Cells[columnIndex].Value = false;
                    if (act != null) act(false, oDgv.Rows[e.RowIndex]);
                }
                else
                {
                    oDgv.Rows[e.RowIndex].Cells[columnIndex].Value = true;
                    if (act != null) act(true, oDgv.Rows[e.RowIndex]);
                }
            };
        }

        /// <summary>
        /// 勾选表格中的复选框,勾选行不变色
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="col"></param>
        public static void OnClickCheckCheckBox(this DataGridView dgv, DataGridViewColumn col)
        {
            dgv.CellContentClick += (object s, DataGridViewCellEventArgs e) =>
            {
                if (e.RowIndex == -1) return;
                DataGridView oDgv = (DataGridView)s;
                if (e.ColumnIndex != col.Index) return;
                if ((bool)oDgv.Rows[e.RowIndex].Cells[col.Index].EditedFormattedValue == true)
                {
                    oDgv.Rows[e.RowIndex].Cells[col.Index].Value = false;
                    oDgv.Rows[e.RowIndex].Selected = false;
                }
                else
                {
                    oDgv.Rows[e.RowIndex].Cells[col.Index].Value = true;
                    oDgv.Rows[e.RowIndex].Selected = true;
                }
                oDgv.ClearSelection();
                foreach (DataGridViewRow r in dgv.Rows)
                {
                    if (r.Cells[0].Value == null || !(bool)r.Cells[0].Value) continue;
                    r.Selected = true;
                }
            };
        }

        /// <summary>
        /// 设置下拉列表事件
        /// <para>2012.8.25</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="act"></param>
        public static void OnCommoBoxSelectedIndexChanged(this DataGridView dgv, EventHandler act)
        {
            dgv.EditingControlShowing += (object s, DataGridViewEditingControlShowingEventArgs e) =>
            {
                ComboBox cb = e.Control as ComboBox;
                if (cb == null) return;
                cb.SelectedIndexChanged -= act;
                cb.SelectedIndexChanged += act;
            };
        }


        public static void CheckCheckBox<T>(this DataGridView dgv, int checkboxColumnIndex, string valueColumnName, T[] values)
        {
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                if (values.Contains((T)dgv.Rows[i].Cells[valueColumnName].Value)) dgv.Rows[i].Cells[checkboxColumnIndex].Value = true;
            }
        }

        /// <summary>
        /// 全选
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="columnIndex"></param>
        public static void CheckAllCheckBox(this DataGridView dgv, int columnIndex, bool checkedstate)
        {
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                dgv.Rows[i].Cells[columnIndex].Value = checkedstate;
            }

        }

        /// <summary>
        /// 反选
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="columnIndex"></param>
        public static void CheckInverseCheckBox(this DataGridView dgv, int columnIndex)
        {
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                if ((bool)dgv.Rows[i].Cells[0].EditedFormattedValue == true)
                    dgv.Rows[i].Cells[0].Value = false;
                else
                    dgv.Rows[i].Cells[0].Value = true;
            }
        }

        /// <summary>
        /// 获取指定坐标的行所指定的行中某单元格的值
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="p"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        public static object GetValueAtPoint(this DataGridView dgv, Point p, int columnIndex)
        {
            int rowid = dgv.HitTest(p.X, p.Y).RowIndex;
            if (rowid == -1) return null;
            return dgv.Rows[rowid].Cells[columnIndex].Value;
        }

        /// <summary>
        /// 获取指定列的值
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="colname"></param>
        /// <returns></returns>
        public static IList<string> GetSelectedValue(this DataGridView dgv, string colname)
        {
            IList<string> list = new List<string>();
            DataGridViewRow r = null;
            foreach (DataGridViewCell c in dgv.SelectedCells)
            {
                if (c.OwningRow == r) continue;
                r = c.OwningRow;
                list.Add(r.Cells[colname].Value.ToString());
            }
            return list;
        }

        /// <summary>
        /// 选择指定坐标所在的行
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="p"></param>
        public static void SelectRowAtPoint(this DataGridView dgv, Point p)
        {
            int rowid = dgv.HitTest(p.X, p.Y).RowIndex;
            if (rowid == -1) return;
            dgv.ClearSelection();
            dgv.Rows[rowid].Selected = true;
        }

        public static void SelectRowByRowID(this DataGridView dgv, int rowid)
        {
            if (rowid == -1 || rowid >= dgv.RowCount) return;
            dgv.ClearSelection();
            dgv.Rows[rowid].Selected = true;
        }

        /// <summary>
        /// 鼠标右键选择全行
        /// </summary>
        /// <param name="dgv"></param>
        public static void OnRightMouseDownSelectRow(this DataGridView dgv)
        {
            dgv.MouseDown += (object s, MouseEventArgs e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    dgv.SelectRowAtPoint(e.Location);
                }
            };
        }

        /// <summary>
        /// 是除指定列之外的所有列不可编辑
        /// <para>2012.8.25</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="editcolumns"></param>
        public static void LockColumns(this DataGridView dgv, params string[] editcolumns)
        {
            foreach (DataGridViewColumn c in dgv.Columns)
            {
                if (editcolumns.Contains(c.Name)) continue;
                c.ReadOnly = true;
            }
        }

        /// <summary>
        /// 设置DataGridViewComboBoxColumn的数据源
        /// </summary>
        /// <param name="cbCol"></param>
        /// <param name="dt"></param>
        /// <param name="dataproperty"></param>
        public static void SetDataSource(this DataGridViewComboBoxColumn cbCol, DataTable dt, string dataproperty = "")
        {
            cbCol.DataSource = dt;
            cbCol.DisplayMember = "Name";
            cbCol.ValueMember = "ID";
            if (dataproperty.Length > 0) cbCol.DataPropertyName = dataproperty;
        }

        /// <summary>
        /// 列格式化为货币值
        /// <para>2012-9-11</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="fmt"></param>
        /// <param name="colnames"></param>
        public static void CellFormattingDecimal(this DataGridView dgv, string fmt, params string[] colnames)
        {
            if (colnames == null || string.IsNullOrEmpty(fmt)) return;
            dgv.CellFormatting += (object s, DataGridViewCellFormattingEventArgs e) =>
            {
                if (e.Value != null && colnames.Contains(dgv.Columns[e.ColumnIndex].Name)) e.Value = ((decimal)e.Value).ToString(fmt);
            };
        }

        /// <summary>
        /// 列格式化为时间值
        /// <para>2012-9-11</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="fmt"></param>
        /// <param name="colnames"></param>
        public static void CellFormattingDateTime(this DataGridView dgv, string fmt, params string[] colnames)
        {
            if (colnames == null || string.IsNullOrEmpty(fmt)) return;
            dgv.CellFormatting += (object s, DataGridViewCellFormattingEventArgs e) =>
            {
                if (colnames.Contains(dgv.Columns[e.ColumnIndex].Name)) e.Value = ((DateTime)e.Value).ToString(fmt);
            };
        }

        /// <summary>
        /// 获取单元格的字符串值
        /// <para>2012-9-11</para>
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public static string GetString(this DataGridViewCell cell)
        {
            return cell.Value == null ? string.Empty : cell.Value.ToString();
        }

        /// <summary>
        /// 获取当前单元格的值
        /// </summary>
        /// <param name="dvg"></param>
        /// <param name="cellname"></param>
        /// <returns></returns>
        public static object GetCurrentValue(this DataGridView dvg, string cellname, object defv = null)
        {
            return dvg.CurrentCell == defv ? null : dvg.CurrentCell.OwningRow.Cells[cellname].Value;
        }

        /// <summary>
        /// 隐藏某行
        /// <para>2012-9-12</para>
        /// </summary>
        /// <param name="dgv"></param>
        public static void HideRow(this DataGridView dgv, Form frm)
        {
            CurrencyManager cm = (CurrencyManager)frm.BindingContext[dgv.DataSource];
            cm.SuspendBinding();
            dgv.CurrentCell.OwningRow.Visible = false;
            cm.ResumeBinding();
        }

        /// <summary>
        /// 获取允许参与搜索的列
        /// <para>不允许搜索的列名称后面加下划线"_"</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <returns></returns>
        public static DataTable GetSearchableColumns(this DataGridView dgv)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Name");
            dt.Columns.Add("Type");
            dt.Columns.Add("Default");
            dt.Columns.Add("DataSource");
            int ipos;
            foreach (DataGridViewColumn c in dgv.Columns)
            {
                if (c.Name.EndsWith("_")) continue;
                ipos = c.Name.IndexOf("__");
                if (ipos > -1)
                {
                    dt.Rows.Add(c.DataPropertyName, c.HeaderText, c.Name.Substring(ipos + 2), "", "");
                }
                else
                {
                    dt.Rows.Add(c.DataPropertyName, c.HeaderText, "text", "", "");
                }
            }
            return dt;
        }

        /// <summary>
        /// 配置表格允许用户自定义拖动列，并记录列的位置
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="datagridviewName"></param>
        /// <param name="userName"></param>
        /// <param name="sitetag"></param>
        public static void AllowCustomerOrderColumns(this DataGridView dgv, string datagridviewName, string userName, string sitetag = "Demo")
        {
            dgv.AllowUserToOrderColumns = true;
            string s = ADF.ADFS.Current.Site.GetFolder(sitetag).GetFolder(userName).GetFolder("UIConfig").GetFolder("DataGridView").GetFileText(datagridviewName);
            if (s.Length > 0)
            {
                System.Collections.Generic.Dictionary<string, int> dict = new System.Collections.Generic.Dictionary<string, int>();
                foreach (string a in s.Split(';'))
                {
                    if (a.Length == 0) continue;
                    string[] b = a.Split(':');
                    dict.Add(b[0], b[1].ToInt());
                }
                int colCount = dgv.Columns.GetColumnCount(DataGridViewElementStates.Visible);
                foreach (DataGridViewColumn c in dgv.Columns)
                {
                    if (!c.Visible) continue;
                    if (dict.ContainsKey(c.Name) && dict[c.Name] < colCount) c.DisplayIndex = dict[c.Name];
                }
            }
            dgv.ColumnDisplayIndexChanged += (object sender, DataGridViewColumnEventArgs e) =>
            {

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (DataGridViewColumn c in dgv.Columns)
                {
                    if (!c.Visible) continue;
                    sb.AppendFormat("{0}:{1};", c.Name, c.DisplayIndex);
                }
                ADF.ADFS.Current.Site.GetFolder(sitetag).GetFolder(userName).GetFolder("UIConfig").GetFolder("DataGridView").SetFileText(datagridviewName, sb.ToString().TrimEnd(';'));
            };
        }

        /// <summary>
        /// 保存到Excel
        /// <para>2012-11-20</para>
        /// </summary>
        /// <param name="dgv"></param>
        public static bool SaveAsExcel(this DataGridView dgv, Func<DataGridViewCell, string> getCellValue = null)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Title = "保存到Excel文件";
            sfd.Filter = "Excel文件(*.xls) |*.xls |所有文件(*.*) |*.*";
            sfd.FilterIndex = 1;
            if (sfd.ShowDialog() != DialogResult.OK) return false;
            string FileName = sfd.FileName;
            if (File.Exists(FileName)) File.Delete(FileName);
            FileStream objFileStream;
            StreamWriter objStreamWriter;
            string strLine = string.Empty;
            objFileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
            objStreamWriter = new StreamWriter(objFileStream, System.Text.Encoding.Unicode);
            for (int i = 0; i < dgv.Columns.Count; i++)
            {
                if (dgv.Columns[i].Visible == true)
                {
                    strLine = strLine + dgv.Columns[i].HeaderText.ToString() + Convert.ToChar(9);
                }
            }
            objStreamWriter.WriteLine(strLine);
            strLine = string.Empty;

            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                if (dgv.Columns[0].Visible == true)
                {
                    if (dgv.Rows[i].Cells[0].Value == null)
                        strLine = strLine + " " + Convert.ToChar(9);
                    else
                        strLine = strLine + dgv.Rows[i].Cells[0].Value.ToString() + Convert.ToChar(9);
                }
                for (int j = 1; j < dgv.Columns.Count; j++)
                {
                    if (dgv.Columns[j].Visible == true)
                    {
                        if (dgv.Rows[i].Cells[j].Value == null)
                            strLine = strLine + " " + Convert.ToChar(9);
                        else
                        {
                            string rowstr = "";
                            rowstr = getCellValue == null ? dgv.Rows[i].Cells[j].Value.ToString() : getCellValue(dgv.Rows[i].Cells[j]);
                            if (rowstr.IndexOf("\r\n") > 0)
                                rowstr = rowstr.Replace("\r\n", " ");
                            if (rowstr.IndexOf("\t") > 0)
                                rowstr = rowstr.Replace("\t", " ");
                            strLine = strLine + rowstr + Convert.ToChar(9);
                        }
                    }
                }
                objStreamWriter.WriteLine(strLine);
                strLine = "";
            }
            objStreamWriter.Close();
            objFileStream.Close();
            return true;
        }

        /// <summary>
        /// 指定列是否包含指定的值
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="value"></param>
        /// <param name="colIndex"></param>
        /// <returns></returns>
        public static bool ContainValue(this DataGridView dgv, object value, int colIndex)
        {
            if (dgv.Rows.Count == 0) return false;
            foreach (DataGridViewRow r in dgv.Rows)
            {
                if (r.Cells[colIndex].Value == value) return true;
            }
            return false;
        }
        #region 外观

        /// <summary>
        /// 设置列的标题栏背景
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="bg"></param>
        /// <param name="height"></param>
        public static void SetColumnHeadersStyle(this DataGridView dgv, Color bg, int height = 23)
        {
            dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
            dgv.EnableHeadersVisualStyles = false;
            dgv.ColumnHeadersHeight = height;
            dgv.ColumnHeadersDefaultCellStyle.BackColor = bg;
        }
        #endregion

        #region 值操作

        #endregion

        /// <summary>
        /// 设置数据表的数据源排序
        /// <para>2012-12-7</para>
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="act"></param>
        /// <param name="colsIndexs"></param>
        public static void SetOrderBySource(this DataGridView dgv, Action<string> act, params int[] colsIndexs)
        {
            dgv.ColumnHeaderMouseClick += (object o, DataGridViewCellMouseEventArgs e) =>
            {
                if (colsIndexs.Contains(e.ColumnIndex))
                {
                    DataGridViewColumn col = dgv.Columns[e.ColumnIndex];
                    col.SortMode = DataGridViewColumnSortMode.Programmatic;
                    if (col.HeaderCell.SortGlyphDirection == SortOrder.Ascending)
                    {
                        act(string.Format("{0} {1}", col.DataPropertyName, "asc"));
                        col.HeaderCell.SortGlyphDirection = SortOrder.Descending;
                    }
                    else
                    {
                        act(string.Format("{0} {1}", col.DataPropertyName, "desc"));
                        col.HeaderCell.SortGlyphDirection = SortOrder.Ascending;
                    }
                }
            };
        }

        /// <summary>
        /// 获取表格的查询列名称
        /// </summary>
        /// <param name="dgv"></param>
        /// <returns></returns>
        /// <remarks>1.0.0 2013-12-17 sutroon</remarks>
        public static string GetQueryFields(this DataGridView dgv)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (DataGridViewColumn c in dgv.Columns)
            {
                if (c.DataPropertyName == c.HeaderText)
                {
                    sb.AppendFormat(" {0},", c.DataPropertyName);
                    continue;
                }
                sb.AppendFormat(" {0} as '{1}',", c.DataPropertyName, c.HeaderText);
            }
            return sb.ToString().TrimEnd(',');
        }

        /// <summary>
        /// 添加表格列
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dgv"></param>
        /// <param name="headText"></param>
        /// <param name="dataPropertyName"></param>
        /// <param name="format"></param>
        /// <param name="visible"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        /// <remarks>2013-12-18 sutroon</remarks>
        public static T AddColumn<T>(this DataGridView dgv, string headText, string dataPropertyName = null, string format = null, bool visible = true, int width = -1, string name = null) where T : DataGridViewColumn, new()
        {
            if (string.IsNullOrEmpty(name)) name = "col" + headText;
            if (dgv.Columns.Contains(name))
            {
                MessageBox.Show(string.Format("Column [{0}] Exists!", name));
                return (T)dgv.Columns[name];
            }
            T col = new T() { HeaderText = headText, Name = name };
            if (dataPropertyName != null) col.DataPropertyName = string.IsNullOrEmpty(dataPropertyName) ? headText : dataPropertyName;
            if (!string.IsNullOrEmpty(format)) col.DefaultCellStyle = new DataGridViewCellStyle() { Format = format };
            if (width > -1) col.Width = width;
            if (!visible) col.Visible = visible;
            dgv.Columns.Add(col);
            return col;
        }

    }
}
